package cn.faifai.desktop.view.components.menus;

import cn.faifai.desktop.enums.SecondaryClickOperation;
import cn.faifai.desktop.events.ShowTagEditDialogEvent;
import cn.faifai.framework.utils.SingleEvenBus;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TagTreeItemMenu {
    private ContextMenu contextMenu;

    private TagTreeItemMenu(){
        contextMenu = new ContextMenu();

        MenuItem createTag = new MenuItem("新建标签");
        createTag.setOnAction(e -> SingleEvenBus.getInstance().post(new ShowTagEditDialogEvent(SecondaryClickOperation.ADD.getOperation())));

        MenuItem deleteTag = new MenuItem("删除标签");
        deleteTag.setOnAction(e -> SingleEvenBus.getInstance().post(new ShowTagEditDialogEvent(SecondaryClickOperation.DELETE.getOperation())));

        MenuItem updateTag = new MenuItem("重命名标签");
        updateTag.setOnAction(e -> SingleEvenBus.getInstance().post(new ShowTagEditDialogEvent(SecondaryClickOperation.UPDATE.getOperation())));



        contextMenu.getItems().addAll(createTag, deleteTag, updateTag);
    }

    public static class SingletonHolder {
        private static final TagTreeItemMenu INSTANCE = new TagTreeItemMenu();


    }

    public static TagTreeItemMenu getInstance(){
        return TagTreeItemMenu.SingletonHolder.INSTANCE;
    }

    public static ContextMenu getMenu() {
        return TagTreeItemMenu.SingletonHolder.INSTANCE.contextMenu;
    }
}
